﻿using SqlSugar;

namespace CoreCms.Net.Repository
{
    internal static class SqlSugarExtensions
    {
        internal static ISugarQueryable<T> WithNoLockOrNot<T>(this ISugarQueryable<T> query, bool @lock = false)
        {
            if (@lock)
            {
                query = query.With(SqlWith.NoLock);
            }

            return query;
        }

        /// <summary>
        /// 是否启用锁
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="lock"></param>
        /// <param name="dbLockType"></param>
        /// <returns></returns>
        internal static ISugarQueryable<T> WithUseTranLockOrNot<T>(this ISugarQueryable<T> query, bool @lock = false, DbLockType dbLockType = DbLockType.Wait)
        {
            if (@lock)
            {
                query = query.TranLock(dbLockType);
            }

            return query;
        }

    }
}
